home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / Dev / Meshwriter / MeshWriterTest / MeshWriterMain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-12-03  |  13.2 KB  |  458 lines

  1. /* Main-Header File inserted by GenCodeC */
  2. /* Libraries */
  3. #include <libraries/mui.h>
  4. #include <exec/types.h>
  5. #include <workbench/startup.h>
  6.  
  7. /* Prototypes */
  8. #include <clib/muimaster_protos.h>
  9. #include <clib/exec_protos.h>
  10. #include <clib/alib_protos.h>
  11. #include <clib/dos_protos.h>
  12.  
  13. /*  Ansi  */
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17.  
  18. /* Increase stack size */
  19. LONG __stack=8192;
  20. /* GenCodeC header end */
  21.  
  22. /* Include generated by GenCodeC */
  23. #include "MeshWriterGUI.h"
  24.  
  25. #ifndef WITHMWLLIB
  26. #include "/meshlib.h"
  27. #else
  28. #include <meshwriter/meshwriter.h>
  29. #include <pragma/meshwriter_lib.h>
  30. struct MeshWriterBase *MeshWriterBase = NULL;
  31. #endif
  32.  
  33. #include "modules/modules.h"
  34.  
  35. /* Declarations for libraries (inserted by GenCodeC) */
  36. struct Library * IntuitionBase;
  37. struct Library * MUIMasterBase;
  38.  
  39. /* Init() function */
  40. void init( void )
  41. {
  42.     if (!(IntuitionBase = OpenLibrary("intuition.library",37)))
  43.     {
  44.         exit(10);
  45.     }
  46.     if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  47.     {
  48.         CloseLibrary(IntuitionBase);
  49.         exit(20);
  50.     }
  51. #ifdef WITHMWLLIB
  52.     if (!(MeshWriterBase = (APTR) OpenLibrary("meshwriter.library", 0)))
  53.     {
  54.          CloseLibrary(IntuitionBase);
  55.          CloseLibrary(MUIMasterBase);
  56.          exit(30);
  57.      }
  58. #endif
  59. }
  60. /* GenCodeC init() end */
  61.  
  62. /* End() function */
  63. void end( void )
  64. {
  65. #ifdef WITHMWLLIB
  66.     CloseLibrary((APTR) MeshWriterBase);
  67. #endif
  68.     CloseLibrary(MUIMasterBase);
  69.     CloseLibrary(IntuitionBase);
  70. }
  71. /* GenCodeC end() end */
  72.  
  73. /*********************************************************************/
  74.  
  75. /* Main Function inserted by GenCodeC */
  76. int main(int argc,char **argv)
  77. {
  78.     struct ObjApp * App = NULL;    /* Object */
  79.     BOOL    running = TRUE;
  80.     ULONG    signal;
  81.     char   bigstring[512];
  82.     char   *stringarg=NULL,*stringarg2=NULL;
  83.     LONG   longarg=0;
  84.     FILE   *fp=NULL;
  85.     ULONG  mesh=0;    /* Our mesh INITIALIZE IT */
  86.     ULONG  format3d=0,format2d=0,drawmode=0,viewtype=0;    /* Our file formats and drawing modes and viewtype */
  87.     STRPTR *fileformats3d,*fileformats2d,*drawmodes; /* Our arrays of file formats and drawmodes */
  88.     ULONG  retval=0;
  89.     STRPTR sfilename=NULL;
  90.     
  91.  
  92.     /* Program initialisation : generated by GenCodeC */
  93.     init();
  94.     
  95.     /* Create Object : generated by GenCodeC */
  96.     if (!(App = CreateApp()))
  97.     {
  98.         MUI_Request(App->App,App->WI_MAIN,0,"Error","OK","Can't create app");
  99.         end();
  100.     }
  101.  
  102. //as long as no 2d part is correct
  103. set(App->BT_SAVE2D,MUIA_ShowMe,FALSE);
  104.  
  105.     /*Initialize the extensions */
  106.     fileformats3d = (STRPTR *)MWL3DFileFormatNamesGet();
  107.     get(App->CY_FORMAT3D,MUIA_Cycle_Active,&longarg);
  108.     format3d=MWL3DFileFormatIDGet(fileformats3d[longarg]);
  109.     set(App->STR_EXTENSION3D,MUIA_String_Contents,MWL3DFileFormatExtensionGet(format3d));
  110.  
  111.     fileformats2d = (STRPTR *)MWL2DFileFormatNamesGet();
  112.     get(App->CY_FORMAT2D,MUIA_Cycle_Active,&longarg);
  113.     format2d=MWL2DFileFormatIDGet(fileformats2d[longarg]);
  114.     set(App->STR_EXTENSION2D,MUIA_String_Contents,MWL2DFileFormatExtensionGet(format2d));
  115.  
  116.     drawmodes = (STRPTR *)MWLDrawModeNamesGet();
  117.  
  118.     while (running)
  119.     {
  120.         switch (DoMethod(App->App,MUIM_Application_Input,&signal))
  121.         {
  122.             case MUIV_Application_ReturnID_Quit:
  123.                 running = FALSE;
  124.                 break;
  125.  
  126.             case ID_CALCULATE:
  127.                 if((mesh = MWLMeshNew())==NULL) {
  128.                     MUI_Request(App->App,App->WI_MAIN,0,"Error","OK","Can't create the mesh");
  129.                     break;
  130.                 }
  131.                 set(App->WI_MAIN,MUIA_Window_Sleep,TRUE);
  132.  
  133.                 get(App->CY_MESH,MUIA_Cycle_Active,&longarg);
  134.                 switch(longarg) {
  135.                     case 0 :
  136.                         ground(mesh);
  137.                         break;
  138.                     case 1 :
  139.                         circle(mesh);
  140.                         break;
  141.                     case 2 :
  142.                         checkboard(mesh);
  143.                         break;
  144.                     case 3 :
  145.                         pyramid(mesh);
  146.                         break;
  147.                     case 4 :
  148.                         cube(mesh);
  149.                         break;
  150.                     case 5 :
  151.                         cubetower(mesh);
  152.                         break;
  153.                     case 6 :
  154.                         wave(mesh);
  155.                         break;
  156.                     case 7 :
  157.                         ripples(mesh);
  158.                         break;
  159.                     case 8 :
  160.                         galaxy(mesh);
  161.                         break;
  162.                     case 9 :
  163.                         landscape(mesh);
  164.                         break;
  165.                     case 10 :
  166.                         pawn(mesh);
  167.                         break;
  168.                 }
  169.                 
  170.                 MWLMeshCameraLightDefaultSet(mesh);
  171.  
  172.                 MWLMeshNameGet(mesh,&sfilename);
  173.                 set(App->STR_PA_FILE3D,MUIA_String_Contents,sfilename);
  174.                 set(App->STR_PA_FILE2D,MUIA_String_Contents,sfilename);
  175.                 
  176.                 set(App->WI_MAIN,MUIA_Window_Sleep,FALSE);
  177.                 break;
  178.             /* end of case ID_CALCULATE */
  179.             case ID_NEW:
  180.                 /*
  181.                 ** Delete the mesh to make a new one
  182.                 */
  183.                 set(App->WI_MAIN,MUIA_Window_Sleep,TRUE);
  184.                 MWLMeshDelete(mesh);
  185.                 mesh=0; /* INITIALIZE IT */
  186.                 set(App->WI_MAIN,MUIA_Window_Sleep,FALSE);
  187.                 break;
  188.             /* end of case ID_NEW */                
  189.             case ID_ABOUT:                               
  190.                 get(App->App,MUIA_Application_Version,&stringarg);
  191.                 sprintf(bigstring,"%s\n\nThis program is FREEWARE\n\n",stringarg+6);
  192.                 sprintf(bigstring,"%sAnd by the way, only for tests supposed :)\n\n",bigstring);
  193.                 sprintf(bigstring,"%sAuthor:\nStephan Bielmann\nIm Dorf 2\n",bigstring);                                  
  194.                 sprintf(bigstring,"%sCH-1718 Rechthalten\nURL:http://www.rega-sense.ch/~sbielmann/\nE-Mail:stephan.bielmann@rega-sense.ch\n\n",bigstring);
  195.                 
  196.                 MUI_Request(App->App,App->WI_MAIN,0,"About","OK",bigstring);
  197.                 break;
  198.             /* end of case ID_ABOUT */
  199.             case ID_INFO:
  200.                 sprintf(bigstring,"The mesh has :\n\n");
  201.                 sprintf(bigstring,"%s%ld vertices\n",bigstring,MWLMeshNumberOfVerticesGet(mesh));
  202.                 sprintf(bigstring,"%s%ld polygons\n",bigstring,MWLMeshNumberOfPolygonsGet(mesh));
  203.                 sprintf(bigstring,"%s%ld materials\n",bigstring,MWLMeshNumberOfMaterialsGet(mesh));
  204.                 
  205.                 MUI_Request(App->App,App->WI_MAIN,0,"Information","OK",bigstring);
  206.                 break;
  207.             /* end of case ID_INFO */
  208.             case ID_SAVE3D:
  209.                 /*
  210.                 ** Save the mesh as 3D file
  211.                 */
  212.                 get(App->PA_FILE3D,MUIA_String_Contents,&stringarg);
  213.                 if(strlen(stringarg)==0) {
  214.                     MUI_Request(App->App,App->WI_MAIN,0,"Warning","OK","You forgot to enter a filename.");
  215.                     break;
  216.                 }
  217.  
  218.                 get(App->STR_COPYRIGHT,MUIA_String_Contents,&stringarg2);
  219.                 MWLMeshCopyrightSet(mesh,stringarg2);
  220.                 
  221.                 get(App->CY_FORMAT3D,MUIA_Cycle_Active,&longarg);
  222.                 format3d=MWL3DFileFormatIDGet(fileformats3d[longarg]);
  223.                 get(App->STR_EXTENSION3D,MUIA_String_Contents,&stringarg2);
  224.                 
  225.                 if (strlen(stringarg2)) sprintf(bigstring,"%s.%s",stringarg,stringarg2);
  226.                 else strcpy(bigstring,stringarg);
  227.                 
  228.                 if((fp=fopen(bigstring,"r"))!=NULL) {
  229.                     fclose(fp);
  230.                     if(!MUI_Request(App->App,App->WI_MAIN,0,"Warning","OK|Cancel","Do you want to overwrite this file ?")) break;
  231.                 }
  232.                 
  233.                 set(App->WI_MAIN,MUIA_Window_Sleep,TRUE);
  234.                 if((retval=MWLMeshSave3D(mesh,format3d,bigstring,NULL))!=RCNOERROR) {
  235.                     sprintf(bigstring,"Could not save the file! RC : %ld",retval);
  236.                     MUI_Request(App->App,App->WI_MAIN,0,"Error","OK",bigstring);
  237.                 }
  238.                 else MUI_Request(App->App,App->WI_MAIN,0,"Information","OK","The file is saved");
  239.                 set(App->WI_MAIN,MUIA_Window_Sleep,FALSE);
  240.                 break;
  241.             /* end of case ID_SAVE2D */                
  242.             case ID_SAVE2D:
  243.                 /*
  244.                 ** Save the mesh as 2D file
  245.                 */
  246.                 get(App->PA_FILE2D,MUIA_String_Contents,&stringarg);
  247.                 if(strlen(stringarg)==0) {
  248.                     MUI_Request(App->App,App->WI_MAIN,0,"Warning","OK","You forgot to enter a filename.");
  249.                     break;
  250.                 }
  251.  
  252.                 get(App->STR_COPYRIGHT,MUIA_String_Contents,&stringarg2);
  253.                 MWLMeshCopyrightSet(mesh,stringarg2);
  254.                 
  255.                 get(App->CY_FORMAT2D,MUIA_Cycle_Active,&longarg);
  256.                 format2d=MWL2DFileFormatIDGet(fileformats2d[longarg]);
  257.                 get(App->STR_EXTENSION2D,MUIA_String_Contents,&stringarg2);
  258.  
  259.                 get(App->CY_VIEWTYPE2D,MUIA_Cycle_Active,&longarg);
  260.                 switch (longarg) {
  261.                     case 0 :
  262.                         viewtype=TVWTOP;
  263.                         break;
  264.                     case 1 :
  265.                         viewtype=TVWBOTTOM;
  266.                         break;
  267.                     case 2 :
  268.                         viewtype=TVWLEFT;
  269.                         break;
  270.                     case 3 :
  271.                         viewtype=TVWRIGHT;
  272.                         break;
  273.                     case 4 :
  274.                         viewtype=TVWFRONT;
  275.                         break;
  276.                     case 5 :
  277.                         viewtype=TVWBACK;
  278.                         break;
  279.                     case 6 :
  280.                         viewtype=TVWPERSP;
  281.                         break;
  282.                     case 7 :
  283.                         viewtype=TVW4SIDES;
  284.                         break;
  285.                 }
  286.  
  287.                 get(App->CY_DRAWMODE2D,MUIA_Cycle_Active,&longarg);
  288.                 drawmode=MWLDrawModeIDGet(drawmodes[longarg]);
  289.                 
  290.                 if (strlen(stringarg2)) sprintf(bigstring,"%s.%s",stringarg,stringarg2);
  291.                 else strcpy(bigstring,stringarg);
  292.                 
  293.                 if((fp=fopen(bigstring,"r"))!=NULL) {
  294.                     fclose(fp);
  295.                     if(!MUI_Request(App->App,App->WI_MAIN,0,"Warning","OK|Cancel","Do you want to overwrite this file ?")) break;
  296.                 }
  297.                 
  298.                 set(App->WI_MAIN,MUIA_Window_Sleep,TRUE);
  299.                 if((retval=MWLMeshSave2D(mesh,format2d,bigstring,viewtype,drawmode,NULL))!=RCNOERROR) {
  300.                     sprintf(bigstring,"Could not save the file! RC : %ld",retval);
  301.                     MUI_Request(App->App,App->WI_MAIN,0,"Error","OK",bigstring);
  302.                 }
  303.                 else MUI_Request(App->App,App->WI_MAIN,0,"Information","OK","The file is saved");
  304.                 set(App->WI_MAIN,MUIA_Window_Sleep,FALSE);
  305.                 break;
  306.  
  307.  
  308.  
  309. /*
  310.  
  311. !! viewtype
  312.                 get(App->PA_FILE,MUIA_String_Contents,&stringarg);
  313.                 if(strlen(stringarg)==0) {
  314.                     MUI_Request(App->App,App->WI_MAIN,0,"Warning","OK","You forgot to enter a filename.");
  315.                     break;
  316.                 }
  317.  
  318.                 get(App->STR_COPYRIGHT,MUIA_String_Contents,&stringarg2);
  319.                 MWLMeshCopyrightSet(mesh,stringarg2);
  320.                 
  321.                 get(App->CY_FORMAT,MUIA_Cycle_Active,&longarg);
  322.                 format=MWL3DFileFormatIDGet(fileformats[longarg]);
  323.                 get(App->STR_EXTENSION,MUIA_String_Contents,&stringarg2);
  324.                 
  325.                 if (strlen(stringarg2)) sprintf(bigstring,"%s.%s",stringarg,stringarg2);
  326.                 else strcpy(bigstring,stringarg);
  327.                 
  328.                 if((fp=fopen(bigstring,"r"))!=NULL) {
  329.                     fclose(fp);
  330.                     if(!MUI_Request(App->App,App->WI_MAIN,0,"Warning","OK|Cancel","Do you want to overwrite t Fè RŒ%D-his file ?")) break;
  331.                 }
  332.                 
  333.                 set(App->WI_MAIN,MUIA_Window_Sleep,TRUE);
  334.                 if(MWLMeshSave3D(mesh,format,bigstring)) MUI_Request(App->App,App->WI_MAIN,0,"Error","OK","Could not save the file!");
  335.                 else MUI_Request(App->App,App->WI_MAIN,0,"Information","OK","The file is saved");
  336.                 set(App->WI_MAIN,MUIA_Window_Sleep,FALSE);
  337.                 break;
  338. */
  339.             /* end of case ID_SAVE2D */
  340.             case ID_FORMAT3D :
  341.                 get(App->CY_FORMAT3D,MUIA_Cycle_Active,&longarg);
  342.                 format3d=MWL3DFileFormatIDGet(fileformats3d[longarg]);
  343.                 set(App->STR_EXTENSION3D,MUIA_String_Contents,MWL3DFileFormatExtensionGet(format3d));
  344.                 break;
  345.             /* end of case ID_FORMAT3D */                
  346.             case ID_FORMAT2D :
  347.                 get(App->CY_FORMAT2D,MUIA_Cycle_Active,&longarg);
  348.                 format2d=MWL2DFileFormatIDGet(fileformats2d[longarg]);
  349.                 set(App->STR_EXTENSION2D,MUIA_String_Contents,MWL2DFileFormatExtensionGet(format2d));
  350.                 break;
  351.             /* end of case ID_FORMAT2D */
  352.             case ID_OKCAMLIG: {
  353.                 TOCLVertex position;
  354.                 TOCLColor color;
  355.                 LONG longa=0;
  356.                 char *string=NULL;
  357.                 
  358.                 get(App->STR_CX,MUIA_String_Contents,&string);
  359.                 position.x=atof(string);
  360.                 get(App->STR_CY,MUIA_String_Contents,&string);
  361.                 position.y=atof(string);
  362.                 get(App->STR_CZ,MUIA_String_Contents,&string);
  363.                 position.z=atof(string);
  364.                 MWLMeshCameraPositionSet(mesh,&position);
  365.  
  366.                 get(App->STR_CLX,MUIA_String_Contents,&string);
  367.                 position.x=atof(string);
  368.                 get(App->STR_CLY,MUIA_String_Contents,&string);
  369.                 position.y=atof(string);
  370.                 get(App->STR_CLZ,MUIA_String_Contents,&string);
  371.                 position.z=atof(string);
  372.                 MWLMeshCameraLookAtSet(mesh,&position);
  373.  
  374.                 get(App->STR_LX,MUIA_String_Contents,&string);
  375.                 position.x=atof(string);
  376.                 get(App->STR_LY,MUIA_String_Contents,&string);
  377.                 position.y=atof(string);
  378.                 get(App->STR_LZ,MUIA_String_Contents,&string);
  379.                 position.z=atof(string);
  380.                 MWLMeshLightPositionSet(mesh,&position);
  381.  
  382.                 get(App->SL_RED,MUIA_Slider_Level,&longa);
  383.                 color.r=longa;
  384.                 get(App->SL_GREEN,MUIA_Slider_Level,&longa);
  385.                 color.g=longa;
  386.                 get(App->SL_BLUE,MUIA_Slider_Level,&longa);
  387.                 color.b=longa;
  388.                 MWLMeshLightColorSet(mesh,&color);
  389.  
  390.                 set(App->WI_MAIN,MUIA_Window_Sleep,FALSE);
  391.  
  392.                 break;
  393.             }
  394.             /* end of case ID_OKCAMLIG */
  395.             case ID_CANCELCAMLIG:
  396.                 set(App->WI_MAIN,MUIA_Window_Sleep,FALSE);
  397.                 
  398.                 break;
  399.             /* end of case ID_CANCELCAMLIG */
  400.             case ID_OPENCAMLIG: {
  401.                 TOCLVertex position;
  402.                 TOCLColor color;
  403.                 char string[80];
  404.                 LONG longa=0;
  405.                 
  406.                 MWLMeshCameraPositionGet(mesh,&position);
  407.                 sprintf(string,"%g",position.x);
  408.                 set(App->STR_CX,MUIA_String_Contents,&string);
  409.                 sprintf(string,"%g",position.y);
  410.                 set(App->STR_CY,MUIA_String_Contents,&string);
  411.                 sprintf(string,"%g",position.z);
  412.                 set(App->STR_CZ,MUIA_String_Contents,&string);
  413.  
  414.                 MWLMeshCameraLookAtGet(mesh,&position);
  415.                 sprintf(string,"%g",position.x);
  416.                 set(App->STR_CLX,MUIA_String_Contents,&string);
  417.                 sprintf(string,"%g",position.y);
  418.                 set(App->STR_CLY,MUIA_String_Contents,&string);
  419.                 sprintf(string,"%g",position.z);
  420.                 set(App->STR_CLZ,MUIA_String_Contents,&string);
  421.  
  422.                 MWLMeshLightPositionGet(mesh,&position);
  423.                 sprintf(string,"%g",position.x);
  424.                 set(App->STR_LX,MUIA_String_Contents,&string);
  425.                 sprintf(string,"%g",position.y);
  426.                 set(App->STR_LY,MUIA_String_Contents,&string);
  427.                 sprintf(string,"%g",position.z);
  428.                 set(App->STR_LZ,MUIA_String_Contents,&string);
  429.  
  430.                 MWLMeshLightColorGet(mesh,&color);
  431.                 longa=color.r;
  432.                 set(App->SL_RED,MUIA_Slider_Level,&longa);
  433.                 longa=color.g;
  434.                 set(App->SL_BLUE,MUIA_Slider_Level,&longa);
  435.                 longa=color.b;
  436.                 set(App->SL_GREEN,MUIA_Slider_Level,&longa);
  437.             
  438.                 break;
  439.             }
  440.  
  441.             case ID_CAMLIGACT:
  442.             /* end of case ID_CAMLIGACT */
  443.  
  444.             /* End computing of IDCMP */
  445.  
  446.             default:
  447.                 break;
  448.         }
  449.         if (running && signal) Wait(signal);
  450.     }
  451.     DisposeApp(App);
  452.     end();
  453. }
  454.  
  455. VOID wbmain (struct WBStartup *wbargs) {
  456.     main(0,NULL);
  457. }
  458.